const Koa = require('koa')
const bodyParser = require('koa-bodyparser')
const _ = require('koa-route')
// mysql
const mysql = require('./mydbmysql')

const app = new Koa()
app.listen(3000, () => console.log('http://localhost:3000'))
app.use(bodyParser())

// 连接数据库 数据库连接池
const db = mysql.createPool()

app.use(_.get('/users', async ctx => {
  let sql = 'select * from users'
  let p = await db.query(sql)
  ctx.body = await p
}))